<!--
	* @author gaohailan
  * @desc 先模创新工作室-创新成果展示
-->
<template>
  <div class="innovation-achievement">
    <el-collapse-transition>
      <div v-show="searchshow" class="common-search merge">
        <span class="svg-container">
          <svg-icon icon-class="search" />
        </span>
        <el-input v-model="listQuery.name" clearable placeholder="输入创新名称搜索" class="search-input" @keyup.enter.native="handleFilter" />
        <div class="common-search-btn">
          <el-button class="filter-item" type="primary" @click="handleFilter">{{ $t('table.search') }}</el-button>
          <el-button class="filter-item" type="primary" @click="resettingBtn">重置</el-button>
          <span class="common-search-more" @click="searchshow = !searchshow">更多筛选条件<i class="el-icon-arrow-down" /></span>
        </div>
      </div>
    </el-collapse-transition>
    <el-collapse-transition>
      <div v-show="!searchshow" class="common-search separate">
        <div class="common-search-inner">
          <el-row :gutter="20">
            <el-col :span="8">
              <div class="search-inner-item">
                <div class="item-label">创新名称</div>
                <el-input v-model="search.name" style="width: 300px;" class="filter-item" placeholder="输入创新名称搜索" />
              </div>
            </el-col>
            <el-col :span="8">
              <div class="search-inner-item">
                <div class="item-label">创新成果分类</div>
                <el-select v-model="search.classifyId" placeholder="请选择">
                  <el-option v-for="(item,index) in classifyList" :key="index" :label="item.name" :value="item.id" />
                </el-select>
              </div>
            </el-col>
          </el-row>
        </div>
        <div class="common-search-btn">
          <el-button type="primary" @click="handleFilter">{{ $t('table.search') }}</el-button>
          <el-button class="filter-item" type="primary" @click="resettingBtn">重置</el-button>
          <span class="common-search-more" @click="searchshow = !searchshow">精简筛选条件<i class="el-icon-arrow-up" /></span>
        </div>
      </div>
    </el-collapse-transition>
    <div class="btn-container">
      <div class="btn-container-title">
        <span>职工创新成果</span>
      </div>
      <div class="btn-btns">
        <el-button style="margin-left: 10px;" @click="handleCreate">新建</el-button>
        <el-button style="margin-left: 10px;" @click="handleDeletes">批量删除</el-button>
      </div>
    </div>
    <div class="table">
      <el-table
        ref="producttable"
        v-loading="listLoading"
        :data="innovateList"
        class="tableScope"
        style="width: 100%"
        :header-cell-style="rowClass"
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" width="55" />
        <el-table-column prop="name" label="创新名称" show-overflow-tooltip />
        <el-table-column prop="state" label="状态" width="80" show-overflow-tooltip>
          <template slot-scope="scope">
            <span>{{ scope.row.state=='1'?'启用':'禁用' }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" fixed="right" align="center" width="200" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button type="text" size="mini" @click="handleUpdate(scope.row)">编辑</el-button>
            <el-button type="text" size="mini" @click="handelDel(scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="listQuery.page"
      :limit.sync="listQuery.limit"
      @pagination="getList"
    />
  </div>
</template>

<script>
import waves from '@/directive/waves' // Waves directive
import Pagination from '@/components/Pagination' // Secondary package based on el-pagination
// import { getToken } from '@/utils/auth'
import {className, queryPage, del} from '../api.js'
// import { specialText, phone, socialCreditCode, orgCode } from '@/utils/validate'
export default {
  name: 'InnovationAchievement',
  components: { Pagination },
  directives: { waves },
  props: [],
  data() {
    return {
      listLoading: false,
      total: 0,
      searchshow: true,
      search: {
        star: '',
        name: '',
        classifyId: ''
      },
      listQuery: {
        page: 1,
        limit: 10,
        name: ''
      },
      multipleSelection: [],
      innovateList: [],
      view: '/API-RESOURCE/webView?fid=',
      classifyList: []
    }
  },
  created() {
    this.getList()
    this.getClassifyList()
  },
  methods: {
    rowClass({ row, rowIndex }) {
      return {
        padding: '5px 0',
        height: '20px',
        background: 'rgba(247,247,248,1)'
      }
    },
    /* 搜索按钮事件*/
    handleFilter() {
      this.listQuery.page = 1
      this.getList()
    },
    resettingBtn() {
      this.listQuery.name = ''
      this.listQuery.page = 1
      this.search.star = ''
      this.search.name = ''
      this.search.classifyId = ''
      this.getList()
    },
    /* 创建*/
    handleCreate() {
      this.$router.push({
        path: this.$filterPath('manage'),
        query: { type: 2}
      })
    },
    /* 编辑*/
    handleUpdate(item) {
      this.$router.push({
        path: this.$filterPath('manage'),
        query: {id: item.id, type: 2}
      })
    },
    /* 选择删除数据*/
    handleSelectionChange(arr) {
      this.multipleSelection = arr
    },
    /* 单删*/
    handelDel(row) {
      this.deleteInnovate(row.id)
    },
    /* 多删*/
    handleDeletes() {
      const arr = []
      if (this.multipleSelection.length > 0) {
        this.multipleSelection.forEach(item => {
          arr.push(item.id)
        })
        var ids = arr.join(',')
        this.deleteInnovate(ids)
      } else {
        this.$message({
          message: '请选择需要删除的数据！',
          type: 'warning'
        })
      }
    },
    /* 获取数据列表*/
    getList(obj) {
      this.listLoading = true
      var query = {
        page: obj ? obj.page : this.listQuery.page,
        pageSize: obj ? obj.limit : this.listQuery.limit
      }
      if (this.searchshow) {
        query.name = this.listQuery.name
      } else {
        query.name = this.search.name
        query.classifyId = this.search.classifyId
      }
      return new Promise((resolve, reject) => {
        queryPage(query).then(response => {
          this.innovateList = response.data.data.rows
          this.total = response.data.data.total
          setTimeout(() => {
            this.listLoading = false
          }, 1 * 1000)
        }).catch(error => {
          reject(error)
          setTimeout(() => {
            this.listLoading = false
          }, 1 * 1000)
        })
      })
    },
    /* 删除列表数据*/
    deleteInnovate(ids) {
      this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        return new Promise((resolve, reject) => {
          del({ids}).then(() => {
            this.$notify({
              title: '成功',
              message: '删除成功',
              type: 'success',
              duration: 2000
            })
            this.getList()
          }).catch(error => {
            reject(error)
          })
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    /* 分类信息获取*/
    getClassifyList() {

      return new Promise((resolve, reject) => {
        className().then(response => {
          this.classifyList = response.data.data
        }).catch(error => {
          reject(error)
        })
      })
    }
  }
}
</script>

<style lang="scss">
$dark_gray: #bfced6;
$mainColor: #18A5FD;
.innovation-achievement{
  padding:20px;
  .common-search {
    background-color: #fff;
    padding: 0 20px;
    margin-bottom: 20px;
    .svg-container {
      padding: 0;
      color: $dark_gray;
      vertical-align: middle;
      display: inline-block;
      &_login {
        font-size: 20px;
      }
    }
    .search-input {
      width: 60%;
      position: relative;
      &:after {
        content: "";
        position: absolute;
        left: -25px;
        right: 0;
        bottom: 8px;
        height: 1px;
        background: rgba(226, 227, 232, 1);
      }
      input {
        outline: none;
        background: transparent;
        border: none;
        outline: medium;
        padding: 0;
        &:focus {
          outline: none;
          background-color: transparent;
        }
      }
    }
    .common-search-btn{
      display: inline-block;
      float: right;
      .el-button.is-round{
        padding: 10px 30px;
        margin-right: 34px;
      }
      .common-search-more{
        font-size: 14px;
        font-weight: 500;
        color: $mainColor;
        cursor: pointer;
        margin-left: 10px;
      }
    }
    &.merge {
      height: 50px;
      line-height: 50px;
    }
    &.separate {
      .common-search-inner {
        padding-top: 10px;
        .search-inner-item {
          .item-label {
            height: 30px;
            line-height: 30px;
            font-size: 14px;
            color: #A6A6A6;
            font-weight: 400;
          }
          .el-input {
            position: relative;
            .el-input__inner {
              border: none;
              padding: 0;
            }
            &:after {
              content: "";
              height: 1px;
              background-color: #E2E3E8;
              position: absolute;
              left: 0;
              right: 0;
              bottom: 0;
            }
          }
        }
        .common-search-btn{
          text-align: center;
          display: block;
          float: none;
          height: 56px;
          line-height: 56px;
        }
      }
      .common-search-btn {
        text-align: center;
        display: block;
        float: none;
        height: 56px;
        line-height: 56px;
      }
    }
  }
  .btn-container {
    display: flex;
    height: 36px;
    line-height: 36px;
    margin-top: 15px;
    .btn-container-title {
      flex: 1;
      height: 36px;
      line-height: 36px;
      font-size: 16px;
      color: rgba(51, 51, 51, 1);
    }
  }
  .el-dialog {
    .el-dialog__body {
      padding: 20px;
    }
    .el-dialog__footer {
      border-top: 1px solid #E2E3E8;
      padding: 15px 20px;
    }
  }
}
</style>
